﻿using System;
using System.Collections.Generic;
using System.Collections;
using Iesi.Collections.Generic;

namespace Bunian.Core.BusinessObjects
{
    public class Child : IBeneficiary
    {
        #region Private Fields

        private Family _family;
        private Contact _contact;

        private decimal _baseIncome;
        private long _beneficiaryId;
        private IList<Tender> _beneficiaryTenders;
        private string _Description { get; set; }

        #endregion

        #region Public Properties

        public virtual Family Family
        {
            get
            {
                return _family;
            }
            set
            {
                _family = value;
            }
        }

        public virtual Contact ContactInfo
        {
            get
            {
                return _contact;
            }
            set
            {
                _contact = value;
            }
        }

        #endregion

        #region IBeneficiary Members

        public virtual decimal BaseIncome
        {
            get
            {
                return _baseIncome;
            }
            set
            {
                _baseIncome = value;
            }
        }

        public virtual string SourcesOfIncome 
        {
            get
            {
                return this.Family.SourcesOfIncome;
            }
            set
            {
                //Do nothing ...
            }
        }

        public virtual decimal Deficiency
        {
            get
            {
                return 1;
            }
            set
            {
                //
            }
        }

        public virtual IList<Tender> BeneficiaryTenders
        {
            get
            {
                return _beneficiaryTenders;
            }
            set
            {
                _beneficiaryTenders = value;
            }
        }

        public virtual string Description
        {
            get
            {
                return _Description;
            }
            set
            {
                _Description = value;
            }
        }

        #endregion

        #region IPersistedObject Members

        public virtual long Id
        {
            get
            {
                return _beneficiaryId;
            }
            set
            {
                _beneficiaryId = value;
            }
        }

        #endregion

        public virtual IList<Child> GetOtherFamilyMembers()
        {
            List<Child> result = new List<Child>();

            if (null != this.Family.FamilyMembers)
            {
                foreach (Child chld in this.Family.FamilyMembers)
                {
                    if (chld != this)
                    {
                        result.Add(chld);
                    }
                }
            }

            return result;
        }

        public virtual int GetAgeInYears()
        {
            DateTime now = DateTime.Today;

            DateTime birthday = this.ContactInfo.BirthDate;

            int age = now.Year - birthday.Year;

            if (birthday > now.AddYears(-age))
            {
                age -= 1;
            }

            return age;
        }
    }
}